#ifndef THREADCANETUDP_H
#define THREADCANETUDP_H
#include "ThreadBase.h"

extern "C"
{
#include <stdint.h>
#include <sys/time.h>
}
#include <vector>


//#define MAX_NUM_OF_CAN_ID 0x200

typedef struct _CAN_FRAME
{
    struct timeval timestamp;
    uint32_t id;
    uint8_t data[8];
    uint8_t dlc:4;
    uint8_t IDE:1;
    uint8_t RTR:1;
    uint8_t new_msg:1;
}CAN_FRAME;

typedef void (*CanMsgHandlerCallback)(CAN_FRAME*, void*);

class ThreadCANETUDP : public ThreadBase
{
public:
    ThreadCANETUDP(const char* target_ip, const char* target_port, const char* local_port);
    ~ThreadCANETUDP();

    void can_send(CAN_FRAME* can_frame);
    void routine();
    void set_msg_handler_callback(CanMsgHandlerCallback callback, void* node);



private:
    int m_sockfd;
    char m_target_ip[32];
    char m_target_port[32];
    
    CanMsgHandlerCallback msg_handler_callback;
    void* parent;

};

#endif // THREADCANETUDP_H
